home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / TinyMeter / Source / TinyMeter_main / misc.c < prev    next >
C/C++ Source or Header  |  1997-02-27  |  4KB  |  151 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/imageclass.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/cghooks.h>
  12. #include <intuition/icclass.h>
  13. #include <intuition/classes.h>
  14. #include <intuition/sghooks.h>
  15. #include <intuition/screens.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <utility/tagitem.h>
  20. #include <utility/hooks.h>
  21. #include <string.h>
  22. #include <datatypes/datatypesclass.h>
  23. #include <datatypes/datatypes.h>
  24. #include <datatypes/pictureclass.h>
  25. #include "gaugeclass.h"
  26. #include "tinymeter.h"
  27.  
  28. void BltT(struct BitMap *src, UWORD s_x, UWORD s_y, struct RastPort *dest, UWORD d_x, UWORD d_y, UWORD w, UWORD h, UBYTE t_col, UBYTE *mask)
  29. {
  30.     ULONG           i,k;
  31.     UBYTE           *s1,*s2,*s3;
  32.     BOOL            allocated=FALSE,firstrun=FALSE;
  33.     k = src->BytesPerRow*src->Rows;
  34.     if(!mask) { mask=(UBYTE *)AllocVec(k,MEMF_CHIP); allocated=TRUE; }
  35.     if( mask)
  36.     {
  37.     s3 = mask+k+1;
  38.     for(i=0;i<src->Depth;i++)
  39.     {
  40.         s1 = (UBYTE *)mask;
  41.         s2 = (UBYTE *)src->Planes[i];
  42.         if(firstrun)
  43.         {
  44.         if((1<<i)&t_col) for(;s1<s3;s1++) *s1&=         *(s2++);
  45.         else             for(;s1<s3;s1++) *s1&=       ~(*(s2++));
  46.         }
  47.         else
  48.         {
  49.         firstrun=TRUE;
  50.         if((1<<i)&t_col) for(;s1<s3;s1++) *s1=(0xFF)&  (*(s2++));
  51.         else             for(;s1<s3;s1++) *s1=(0xFF)&(~(*(s2++)));
  52.         }
  53.     }
  54.     BltMaskBitMapRastPort(src,s_x,s_y,dest,d_x,d_y,w,h,0xb0,mask);
  55.     if(allocated) FreeVec(mask);
  56.     }
  57. }
  58.  
  59. void DrawDTObject(Object *src, UWORD s_x, UWORD s_y, struct RastPort *dest, UWORD d_x, UWORD d_y, WORD w, WORD h, BOOL really)
  60. {
  61.     UBYTE               *ColorTable;
  62.     struct BitMapHeader *bmhd;
  63.     struct BitMap       *bm;
  64.     GetDTAttrs(src,PDTA_BitMapHeader,&bmhd,PDTA_DestBitMap,&bm,PDTA_ColorTable,&ColorTable,TAG_DONE);
  65.     if(w=-1)w=bmhd->bmh_Width;
  66.     if(h=-1)h=bmhd->bmh_Height;
  67.     if (!bm) GetDTAttrs(src,PDTA_BitMap,&bm,TAG_DONE);
  68.     if((bmhd->bmh_Masking==mskHasTransparentColor)&&(ColorTable)&&(really!=FALSE))
  69.     BltT(bm,s_x,s_y,dest,d_x,d_y,w,h,ColorTable[bmhd->bmh_Transparent],NULL);
  70.     else
  71.     BltBitMapRastPort(bm,s_x,s_y,dest,d_x,d_y,w,h,0xc0);
  72. }
  73.  
  74. struct GAU_Color *GetGaugePen(WORD pen)
  75. {
  76.     static struct GAU_Color dummycol={ TRUE, 0, 0, 0 };
  77.     dummycol.red=pen; return(&dummycol);
  78. }
  79.  
  80. int my_strlen(char s[])
  81. {
  82.    int i=0; while (s[i]!='\0')++i; return(i);
  83. }
  84.  
  85. UBYTE long_2_string_with_thousand(ULONG num, char output[], char point, BOOL negative)
  86. {
  87.     char             output_private[16];
  88.     char             n      = 0;
  89.     char             n_1    = 0;
  90.     if(negative)output[n_1++]='-';
  91.     sprintf(output_private,"%12ld",num);
  92.     while(output_private[n]==0x20)n++;
  93.     for(;(output_private[n]!=0)&(output_private[n]!=0x20);n++)
  94.     {
  95.     output[n_1++]=output_private[n];
  96.     if((n==2)||(n==5)||(n==8)) output[n_1++]=(char)point;
  97.     }
  98.     output[n_1]=0;
  99.     return((UBYTE)n_1);
  100. }
  101.  
  102. void draw_border_new( struct RastPort *rp,ULONG x, ULONG y, ULONG width, ULONG height, int b_col1, int b_col2 )
  103. {
  104.     width--;height--;
  105.     SetAPen(rp,b_col1);
  106.     RectFill(rp,x,y,x,y+height);
  107.     RectFill(rp,x,y,x+width,y);
  108.     SetAPen(rp,b_col2);
  109.     RectFill(rp,x+width,y,x+width,y+height);
  110.     RectFill(rp,x,y+height,x+width,y+height);
  111. }
  112.  
  113. void my_RectFill(struct RastPort *rp,WORD x,WORD y,WORD width,WORD height)
  114. {
  115.     if(((x+width)>1)&&((y+height)>1)) RectFill(rp,x,y,x+width-1,y+height-1);
  116. }
  117.  
  118. void my_Blit(struct RastPort *src, WORD topx, WORD topy, struct RastPort *dest, WORD dtopx, WORD dtopy, WORD width, WORD height)
  119. {
  120.     ClipBlit(src,topx,topy,dest,dtopx,dtopy,width,height,0xC0);
  121. }
  122.  
  123. void FreePenNew( struct Screen *scr, struct GAU_Color *col,ULONG number, ULONG *Pens)
  124. {
  125.     if(!col->pen) ReleasePen(scr->ViewPort.ColorMap,Pens[number]);
  126. }
  127.  
  128. UWORD obtainPen( struct Screen *src, struct GAU_Color *scr)
  129. {
  130.     return((UWORD)(scr->pen ? scr->red : ObtainBestPenA(src->ViewPort.ColorMap, scr->red, scr->green, scr->blue, 0L)));
  131. }
  132.  
  133. void GetPenNew(struct Screen *scr,struct GAU_Color *col,ULONG number, BOOL *PorC, ULONG *Pens)
  134. {
  135.     PorC[number]= col->pen ? FALSE    : TRUE;
  136.     Pens[number]= obtainPen(scr,col);
  137. }
  138.  
  139. struct TextFont *OpenTopaz()
  140. {
  141.     static struct TextAttr topaz_font =
  142.     {
  143.     "topaz.font",
  144.     8,
  145.     0,
  146.     FPF_ROMFONT,
  147.     };
  148.     return((struct TextFont *)OpenFont( &topaz_font));
  149. }
  150.  
  151.